<template>
  <el-aside :width="width">
    <h4>千锋管理系统</h4>
    <el-menu :collapse="collapse" router :default-active="$route.path" background-color="#2D3436">
      <el-menu-item index="/home">首页</el-menu-item>
      <el-sub-menu class="mbx" v-for="item in list" :index="`/home/${item.path}`" :key="`/home/${item.path}`">
        <template #title>
          <el-icon>
            <Location />
          </el-icon>
          <span>{{item.label}}</span>
        </template>
        <el-menu-item
          v-for="subitem in item.children"
          :index="`/home/${item.path}/${subitem.path}`"
          :key="`/home/${item.path}/${subitem.path}`"
        >
          <span>{{subitem.label}}</span>
        </el-menu-item>
      </el-sub-menu>
    </el-menu>
  </el-aside>
</template>

<script>
import { Location } from '@element-plus/icons-vue';
import { routes } from '../router/index';
export default {
  props: ['width', 'collapse'],
  components: {
    Location
  },
  computed: {
    userInfo() {
      return this.$store.state.userInfo;
    },
    routesData() {
      let dataCopy = JSON.parse(JSON.stringify(routes[2].children));
      dataCopy[1].children.pop();
      return dataCopy;
    },
    list() {
      return this.userInfo.adminname === 'admin' ? this.routesData : this.userInfo.checkedkeys;
    }
  }
};
</script>
<style scoped>
.el-aside {
  background: #2d3436;
  color: white;
}
.el-menu {
  border: 0;
  color: white;
}
.el-menu-item,
.el-sub-menu span,
.el-icon {
  color: #f2fff2 !important;
}
</style>